<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Persistent Connections</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="mysqlnd.incompatibilities.html">« Incompatibilities</a></li>
      <li style="float: right;"><a href="mysqlnd.stats.html">Statistics »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.mysqlnd.html">Mysqlnd</a></li>
    <li>Persistent Connections</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="mysqlnd.persist" class="chapter">
 <h1>Persistent Connections</h1>

 <p class="para">
  <em class="emphasis">Using Persistent Connections</em>
 </p>
 <p class="para">
  If <code class="literal">mysqli</code> is used with <code class="literal">mysqlnd</code>,
  when a persistent connection is created it generates a
  <code class="literal">COM_CHANGE_USER</code>
  (<code class="literal">mysql_change_user()</code>) call on the server. This
  ensures that re-authentication of the connection takes place.
 </p>
 <p class="para">
  As there is some overhead associated with the
  <code class="literal">COM_CHANGE_USER</code> call, it is possible to switch this
  off at compile time. Reusing a persistent connection will then
  generate a <code class="literal">COM_PING</code> (<code class="literal">mysql_ping</code>)
  call to simply test the connection is reusable.
 </p>
 <p class="para">
  Generation of <code class="literal">COM_CHANGE_USER</code> can be switched off
  with the compile flag
  <code class="literal">MYSQLI_NO_CHANGE_USER_ON_PCONNECT</code>. For example:
 </p>
<div class="example-contents">
<div class="cdata"><pre>
shell# CFLAGS=&quot;-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT&quot; ./configure --with-mysql=/usr/local/mysql/ --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql/bin/mysql_config --enable-debug &amp;&amp; make clean &amp;&amp; make -j6
</pre></div>
</div>

 <p class="para">
  Or alternatively:
 </p>
<div class="example-contents">
<div class="cdata"><pre>
shell# export CFLAGS=&quot;-DMYSQLI_NO_CHANGE_USER_ON_PCONNECT&quot;
shell# configure --whatever-option
shell# make clean
shell# make
</pre></div>
</div>

 <p class="para">
  Note that only <code class="literal">mysqli</code> on <code class="literal">mysqlnd</code>
  uses <code class="literal">COM_CHANGE_USER</code>. Other extension-driver
  combinations use <code class="literal">COM_PING</code> on initial use of a
  persistent connection.
 </p>
</div>
</div></div></body></html>